home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Login2.aspx.cs401
< prev
next >
Wrap
Text File
|
2007-12-08
|
15KB
|
366 lines
using System;
using System.IO;
using System.Net;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Xml;
using GBPVR.Public;
namespace gbweb
{
/// <summary>
/// Summary description for Login.
/// </summary>
public partial class Login2 : Page
{
protected string salt;
private string requiredGuestPasswordHash;
private String requiredUsername;
private String requiredPasswordHash;
bool use_new_themes = false;
private string hostAddress = string.Empty;
protected Settings guideParams;
protected void Page_Load(object sender, EventArgs e)
{
getTheme();
Session["GuideStartTime"] = null;
Session["NotGuestUser"] = "true";
Logger.Info("Loading Config...");
XmlDocument configDoc = Global.Config;
// extract username and password
requiredUsername = "admin";
requiredPasswordHash = string.Empty;
XmlNode node = configDoc.SelectSingleNode("/settings/WebUsername");
if (node != null)
{
requiredUsername = node.InnerText;
}
node = configDoc.SelectSingleNode("/settings/WebPassword");
if (node != null)
{
requiredPasswordHash = node.InnerText;
}
guideParams = Global.Settings;
requiredGuestPasswordHash = guideParams.GuestPassword;
Logger.Info(" ");
Logger.Info("Pulled Credential from Config...");
Logger.Info("User= " + requiredUsername);
Logger.Info("Password = " + requiredPasswordHash);
Logger.Info(" ");
if (!IsPostBack)
{
Logger.Info("Postback not found....now pulling User Host Info...");
if (Request.UserHostAddress.Substring(0, 1) == ":")
{
Logger.Info("IP V6 Detected on Server ");
if (Global.Settings.autologinNets.CheckNumber(GetIP4Address()))
{
hostAddress = GetIP4Address();
Logger.Info("Using IP4 Address: " + hostAddress);
Logger.Info(" ");
CompleteLogin();
}
}
else
{
Logger.Info("IP V4 Detected on Server");
if (Global.Settings.autologinNets.CheckNumber(Request.UserHostAddress))
{
hostAddress = Request.UserHostAddress;
Logger.Info("Using IP4 Address: " + hostAddress);
Logger.Info(" ");
CompleteLogin();
}
}
}
Logger.Info(" ");
Logger.Info("Setting logo attribute to version info...");
//logo.Attributes.Add("title", Global.Settings.GetVersionToolTip());
Logger.Info("Establishing login salt");
// allocate salt if we havn't already
if (Session["LoginSalt"] == null)
{
Session["LoginSalt"] = Guid.NewGuid().ToString();
}
salt = (string)Session["LoginSalt"];
Logger.Info("Login salt = " + salt);
Logger.Info("Registering hidden field...LoginButton.UniqueID = " + LoginButton.UniqueID);
Logger.Info(" ");
Page.RegisterHiddenField("__EVENTTARGET", LoginButton.UniqueID);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ID = "LoginButton";
}
#endregion
protected void LoginButton_Click(object sender, EventArgs e)
{
Logger.Info("Loginbutton click detected...");
// check credentials
// generate the expected hash
string expectedHash = FormsAuthentication.HashPasswordForStoringInConfigFile(requiredPasswordHash.ToLower() + salt, "MD5");
string GuestexpectedHash = FormsAuthentication.HashPasswordForStoringInConfigFile(requiredGuestPasswordHash.ToLower() + salt, "MD5");
// direct user to "manage listings" if credentials are correct
invalidCredentialsLabel.Visible = true;
Logger.Info("Now pulling User Host Info...");
if (Request.UserHostAddress.Substring(0, 1) == ":")
{
Logger.Info("IP V6 Detected");
hostAddress = GetIP4Address();
Logger.Info("IP6 Address: " + Request.UserHostAddress);
Logger.Info("IP4 Address: " + hostAddress);
}
else
{
Logger.Info("IP V4 Detected");
hostAddress = Request.UserHostAddress;
Logger.Info("IP4 Address: " + hostAddress);
}
Logger.Info(" ");
Logger.Info("Loading Global Settings.... ");
Logger.Info(" ");
guideParams = Global.Settings;
Logger.Info(" ");
Session["NotGuestUser"] = "true";
Logger.Info("Checking to see if the username and password that were entered match what was pulled from config....");
if ((Username.Text == requiredUsername) &&
(PasswordHash.Value == expectedHash.ToLower()))
{
Logger.Info("User name and password matched for Administrative access...");
Logger.Info(" ");
CompleteLogin();
}
else
{
// Create a StringComparer an comare the hashes.
StringComparer comparer = StringComparer.OrdinalIgnoreCase;
if ((0 == comparer.Compare(PasswordHash.Value, GuestexpectedHash)) &&
Username.Text == guideParams.GuestUser)
{
Session["NotGuestUser"] = "false";
Logger.Info("User name and password matched for Guest access...");
Logger.Info(" ");
CompleteLogin();
}
else
{
Logger.Warning("Failed login for " + Username.Text + " from " + hostAddress);
Logger.Info("Pasword hash value = " + PasswordHash.Value);
Logger.Info("Expected Admin hash value = " + expectedHash.ToLower());
Logger.Info("Expected Guest hash value = " + guideParams.GuestPassword);
}
}
}
private void CompleteLogin()
{
Logger.Info("You have made it to the complete login method....this is a good thing.... ");
string userName = Username.Text;
bool createPersistentCookie = false;
string cookiePath = FormsAuthentication.FormsCookiePath;
string redirectUrl = FormsAuthentication.GetRedirectUrl(userName, createPersistentCookie);
Uri redirectUri = new Uri(Request.Url, redirectUrl);
Logger.Info("Checking if new theme flag is set.... ");
if (!use_new_themes)
{
Logger.Info("New theme flag is not set... ");
Logger.Info("Checking username not blank, redirect uri = request path... ");
if ((Username.Text.Length == 0) && (
(string.Compare(redirectUri.LocalPath, Request.ApplicationPath + "/Admin2.aspx", true) == 0)))
{
Logger.Info("User name was blank and the redirect uri and request path were set to admin2.aspx... ");
Logger.Info(" ");
return;
}
Logger.Info("Checking to see if the redirec uri is equal to default.aspx or logout.aspx ");
if (
(string.Compare(redirectUri.LocalPath, Request.ApplicationPath + "/Default.aspx", true) == 0) ||
(string.Compare(redirectUri.LocalPath, Request.ApplicationPath + "/Logout2.aspx", true) == 0))
{
Logger.Info("Redirect uri was equal to default.aspx or logout.aspx....seting the redirect to guide.aspx...... ");
Logger.Info(" ");
redirectUrl = Request.ApplicationPath + "/Guide2.aspx";
}
else
{
Logger.Info("Redirect uri was not equal to default.aspx or logout.aspx.... ");
Logger.Info(" ");
}
}
else
{
Logger.Info("New theme flag is set...");
Logger.Info("Checking username not blank, redirect uri = request path... ");
if ((Username.Text.Length == 0) && (
(string.Compare(redirectUri.LocalPath, Request.ApplicationPath + "/Admin2.aspx", true) == 0)))
{
Logger.Info("User name was blank and the redirect uri and request path were set to admin2.aspx... ");
Logger.Info(" ");
return;
}
Logger.Info("Checking to see if the redirec uri is equal to default2.aspx or logout2.aspx ");
if (
(string.Compare(redirectUri.LocalPath, Request.ApplicationPath + "/Default.aspx", true) == 0) ||
(string.Compare(redirectUri.LocalPath, Request.ApplicationPath + "/Logout2.aspx", true) == 0))
{
Logger.Info("Redirect uri was equal to default2.aspx or logout2.aspx....seting the redirect to guide2.aspx...... ");
Logger.Info(" ");
redirectUrl = Request.ApplicationPath + "/Guide2.aspx";
}
else
{
Logger.Info("Redirect uri was not equal to default2.aspx or logout2.aspx.... ");
Logger.Info(" ");
}
}
Logger.Info(" ");
if (Username.Text.Length == 0)
{
Logger.Info("Automatic login from " + hostAddress);
Session["NotGuestUser"] = "true";
Logger.Info(" ");
}
else
{
Logger.Info("Successful login for " + Username.Text + " from " + hostAddress);
Logger.Info(" ");
}
Logger.Info("Initializing Forms Authentication.... ");
Logger.Info(" ");
FormsAuthentication.Initialize();
Logger.Info("Setting Forms Authentication Cookie.... ");
Logger.Info("Username = " + Username.Text);
Logger.Info("Cookie Path = " + cookiePath);
Logger.Info(" ");
FormsAuthentication.SetAuthCookie(Username.Text, createPersistentCookie, cookiePath);
Logger.Info("Checking for auto search execution.... ");
if ((guideParams.autoShowSearch || guideParams.autoShowRecord) && (String.Compare(guideParams.lastAutoSearchDate, DateTime.Now.ToShortDateString()) != 0))
{
Logger.Info("Auto Search found and has not yet been executed today.... ");
XmlNode EPGHour = Global.Config.SelectSingleNode("/settings/UpdateEPGHour");
Logger.Info("Checking if it is at least one hour past the EPG update for today.... ");
if (DateTime.Now.Hour + 1 > Convert.ToInt32(EPGHour.InnerText))
{
Logger.Info("It is greater than one hour since todays EPG update.... ");
Logger.Info("Executing auto search.... ");
SavedSearchUtils searchUtil = new SavedSearchUtils();
searchUtil.autoSearch(searchUtil.loadAutoSearches());
Logger.Info("Setting last auto search date to today so this routine does not run again until tommorow.... ");
guideParams.lastAutoSearchDate = DateTime.Now.ToShortDateString();
guideParams.Save();
}
else
{
Logger.Info("Auto search can not execute now since it is not 1 hour greater than todays EPG update.... ");
}
}
else
{
Logger.Info("Auto Search is not set to run or it has aleady run today.... ");
}
Logger.Info(" ");
Logger.Info("Redirecting to the target page.... ");
Logger.Info("Redirect URL = " + redirectUrl);
Response.Redirect(redirectUrl, false);
Logger.Info(" ");
}
public string GetIP4Address()
{
string strIP4Address = String.Empty;
foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (objIP.AddressFamily.ToString() == "InterNetwork")
{
strIP4Address = objIP.ToString();
break;
}
}
return strIP4Address;
}
private void getTheme()
{
use_new_themes = false;
string themeDir = Server.MapPath(Request.ApplicationPath);
if (File.Exists(Path.Combine(themeDir, "select_theme.xml")))
{
XmlDocument configThemes = new XmlDocument();
configThemes.Load(Path.Combine(themeDir, "select_theme.xml"));
XmlNodeList themeConfig = configThemes.SelectNodes("theme_config");
foreach (XmlNode themeOpt in themeConfig)
{
use_new_themes = Convert.ToBoolean(themeOpt.SelectSingleNode("//use_new_themes").InnerText);
}
}
string theme = Convert.ToString(Session["theme"]);
HttpCookie cookie = new HttpCookie("UseNewThemes", use_new_themes.ToString());
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
if (theme != null && theme != "" && !use_new_themes)
{
return;
}
else
{
cookie = Request.Cookies["theme"];
if (cookie != null && cookie.Value.Length > 0)
{
theme = cookie.Value;
}
else
{
theme = "Default";
}
if (use_new_themes)
{
Session["theme"] = "themes2/" + theme;
}
else
{
Session["theme"] = "themes2/" + theme;
}
return;
}
}
}
}